package org.lql.algo.codecrush.week009.question.type.III;

import org.lql.algo.common.TreeNode;

/**
 * @author: liangqinglong
 * @date: 2025-08-20 16:57
 * @description: 104. 二叉树的最大深度 <a href="https://leetcode.cn/problems/maximum-depth-of-binary-tree/description/">...</a>
 **/
public class MaxDepth {

	private int depth;
	private int ans;


	public int maxDepth(TreeNode root) {
		depth = 1;
		ans = 0;
		calc(root);
		return ans;
	}

	public void calc(TreeNode root) {
		if (root == null) {
			return;
		}
		ans = Math.max(ans, depth);
		depth++;
		calc(root.left);
		calc(root.right);
		depth--;
	}
}
